﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.peddler.peddlerMarket {
    import Engine.Managers.*;
    import Classes.*;
    import Transactions.*;
    import Classes.util.*;
    import Classes.effects.*;
    import Classes.LogicComponents.*;
    import Display.*;
    import Modules.stats.experiments.*;

    public class MunicipalComponentPeddlerCenter extends MunicipalComponentBase {

        private var m_progressEndFunction:Function = null;

        public function MunicipalComponentPeddlerCenter(_arg1:Municipal){
            super(_arg1);
        }
        override public function handlePlayAction():void{
            var _local2:String;
            if (((Global.isVisiting()) || (((this.isHarvestable()) && (!(Global.guide.isActive())))))){
                this.m_progressEndFunction = null;
                super.handlePlayAction();
                this.m_municipal.removeStagePickEffect();
                StatsManager.count("municipal", "collect", m_municipal.getItem().name);
                return;
            };
            var _local1:int = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_CTTC_PEDDLERCENTER);
            if (_local1 == ExperimentDefinitions.EXPERIMENT_CTTC_PEDDLERCENTER_VALUE){
                if (!this.hasPeddlerDataFromServer()){
                    this.createPeddlerDataAtServer();
                } else {
                    UI.displayPeddlerMarketDialog();
                };
            } else {
                _local2 = ZLoc.t("Dialogs", "hasNotOpened");
                UI.displayMessage(_local2);
            };
        }
        override public function createStagePickEffect():void{
            if (((((!(Global.isVisiting())) && (this.isHarvestable()))) && (!(Global.guide.isActive())))){
                super.createStagePickEffect();
            } else {
                if (!this.hasPeddlerDataFromServer()){
                    createStagePickEffectHelper(StagePickEffect.PICK_UPGRADE);
                } else {
                    if (this.isDonutNeeded()){
                        createStagePickEffectHelper(StagePickEffect.PICK_PEDDLERCENTER_DONUT);
                    };
                };
            };
        }
        override public function enableUpdateArrow():Boolean{
            if (((((!(this.hasPeddlerDataFromServer())) || (this.isDonutNeeded()))) || (this.isHarvestable()))){
                return (true);
            };
            return (false);
        }
        protected function isDonutNeeded():Boolean{
            if (Global.peddlerManager){
                return (!((Global.peddlerManager.findDonutHungryPeddler() == null)));
            };
            return (false);
        }
        private function createPeddlerDataAtServer():void{
            this.m_progressEndFunction = m_municipal.removeStagePickEffect;
            var _local1:String = ZLoc.t("Dialogs", "initPeddlerCenter");
            this.m_progressEndFunction = this.processUpgrade;
            this.m_municipal.doProgressBar(_local1);
        }
        private function processUpgrade():void{
            UI.displayPeddlerMarketDialog();
            GameTransactionManager.addTransaction(new TProgressPeddlerCenter(this.updateAfterGetPeddlerData), true);
        }
        private function hasPeddlerDataFromServer():Boolean{
            return (((Global.peddlerManager) && (Global.peddlerManager.hasPeddlers())));
        }
        private function updateAfterGetPeddlerData():void{
            this.m_municipal.removeStagePickEffect();
            UI.refreshPeddlerMarketDialogData();
        }
        override public function getProgressBarEndFunction():Function{
            return (this.m_progressEndFunction);
        }
        override public function getToolTipAction():String{
            if (((this.isHarvestable()) && (!(Global.guide.isActive())))){
                return (m_municipal.getGameModeToolTipAction());
            };
            if (this.isDonutNeeded()){
                return (ZLoc.t("Dialogs", "NeedPeddlerCenterDonutToolTip"));
            };
            return (null);
        }
        override protected function isHarvestable():Boolean{
            return ((m_municipal.getState() == HarvestableResource.STATE_GROWN));
        }

    }
}//package Modules.peddler.peddlerMarket 
